//
//  Home2Card1TableViewCell.m
//  SulitLoanDemo
//
//  Created by 虞嘉伟 on 2025/2/19.
//  
  

#import "Home2Card1TableViewCell.h"
#import <YYKit.h>
#import <Masonry.h>


@implementation Home2Card1TableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.avatar.layer.cornerRadius = CGRectGetHeight(self.avatar.bounds)*0.5;
}

- (void)setupUI {
    self.backgroundColor = UIColor.whiteColor;
    
    [self.contentView addSubview:self.bgView];
    [self.contentView addSubview:self.decorate];
    
    [self.bgView addSubview:self.avatar];
    [self.bgView addSubview:self.productName];
    [self.bgView addSubview:self.apply];
    [self.bgView addSubview:self.horizontalDevider];
    [self.bgView addSubview:self.creditLimit];
    [self.bgView addSubview:self.verticalDevider];
    [self.bgView addSubview:self.creditLimitMoney];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentView);
        make.top.equalTo(self.contentView).inset(38);
        make.bottom.equalTo(self.contentView);
    }];
    [self.decorate mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.bgView).inset(20);
        make.bottom.equalTo(self.bgView.mas_top).offset(20);
        make.height.mas_equalTo(58);
    }];
    [self.avatar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_avatar.superview).offset(34);
        make.top.equalTo(_avatar.superview).offset(42);
        make.width.height.mas_equalTo(70);
    }];
    [self.productName setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
    [self.productName setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
    [self.productName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.avatar.mas_right).offset(10);
        make.centerY.equalTo(self.avatar);
    }];
    [self.apply mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.productName.mas_right).offset(10);
        make.right.equalTo(_apply.superview).inset(34);
        make.centerY.equalTo(self.avatar);
        make.height.mas_equalTo(45);
        make.width.mas_equalTo(self.apply.intrinsicContentSize.width+28*2);
    }];
    [self.horizontalDevider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(_horizontalDevider.superview).inset(20);
        make.top.equalTo(self.avatar.mas_bottom).offset(16);
        make.height.mas_equalTo(2);
    }];
    
    [self.creditLimit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_creditLimit.superview).inset(34);
        make.top.equalTo(self.horizontalDevider.mas_bottom).offset(28);
        make.height.mas_equalTo(22);
        make.bottom.equalTo(_creditLimit.superview).inset(28);
    }];
    [self.verticalDevider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.horizontalDevider.mas_bottom).offset(0);
        make.bottom.equalTo(_verticalDevider.superview);
        make.centerX.equalTo(_verticalDevider.superview);
        make.width.mas_equalTo(2);
    }];
    [self.creditLimitMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_creditLimitMoney.superview).inset(34);
        make.centerY.equalTo(self.creditLimit);
        make.top.equalTo(self.horizontalDevider.mas_bottom);
        make.bottom.equalTo(_creditLimitMoney.superview);
    }];
}


- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = UIColorHex(#1B1B1B);
    }
    return _bgView;
}

- (UIImageView *)decorate {
    if (!_decorate) {
        _decorate = [UIImageView new];
        _decorate.contentMode = UIViewContentModeScaleAspectFit;
        _decorate.image = [UIImage imageNamed:@"icon_bar_recommend"];
    }
    return _decorate;
}

- (UIImageView *)avatar {
    if (!_avatar) {
        _avatar = [UIImageView new];
        _avatar.contentMode = UIViewContentModeScaleAspectFit;
        _avatar.image = [UIImage imageNamed:@"icon_circle_gray"];
    }
    return _avatar;
}
- (UILabel *)productName {
    if (!_productName) {
        _productName = [UILabel new];
        _productName.textColor = UIColorHex(#FFFFFF);
        _productName.font = aspectDefaultFont(16);
        _productName.text = @"Product name";
        _productName.numberOfLines = 0;
    }
    return _productName;
}
- (UIButton *)apply {
    if (!_apply) {
        _apply = [UIButton buttonWithType:UIButtonTypeCustom];
        [_apply setTitleColor:UIColorHex(#1B1B1B) forState:UIControlStateNormal];
        _apply.titleLabel.font = aspectDefaultFont(16);
        [_apply setTitle:@"Apply" forState:UIControlStateNormal];
        [_apply setImage:[UIImage imageNamed:@"btn_more_white"] forState:UIControlStateNormal];
        [_apply jk_setImagePosition:LXMImagePositionRight spacing:10];
        _apply.backgroundColor = UIColorHex(#FDC5E0);
        _apply.clipsToBounds = YES;
        _apply.layer.cornerRadius = 45*0.5;
    }
    return _apply;
}
- (DashedLineView *)horizontalDevider {
    if (!_horizontalDevider) {
        _horizontalDevider = [DashedLineView new];
        _horizontalDevider.lineColor = UIColor.whiteColor;
    }
    return _horizontalDevider;
}
- (UILabel *)creditLimit {
    if (!_creditLimit) {
        _creditLimit = [UILabel new];
        _creditLimit.textColor = UIColorHex(#FFFFFF);
        _creditLimit.font = aspectDefaultFont(18);
        _creditLimit.text = @"Credit limit (₱)";
        _creditLimit.numberOfLines = 0;
    }
    return _creditLimit;
}
- (DashedLineView *)verticalDevider {
    if (!_verticalDevider) {
        _verticalDevider = [DashedLineView new];
        _verticalDevider.direction = DLDirectionVertical;
        _verticalDevider.lineColor = UIColor.whiteColor;
    }
    return _verticalDevider;
}
- (UILabel *)creditLimitMoney {
    if (!_creditLimitMoney) {
        _creditLimitMoney = [UILabel new];
        _creditLimitMoney.textColor = UIColorHex(#FFFFFF);
        _creditLimitMoney.font = aspectDefaultFont(40);
        _creditLimitMoney.text = @"50,000";
        _creditLimitMoney.textAlignment = NSTextAlignmentRight;
    }
    return _creditLimitMoney;
}


@end
